package dmir.wikipedia.addons;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 
 * 
 * @author ivo
 *
 */
public class EnglishWikiAreaUtil {
    
    private static final Pattern enAreaPattern = Pattern.compile(
            "\\|\\s*(area_total_km2|area_km2|TotalArea|area_total|area)\\s*=\\s*([\\d,\\.]+)", 
            Pattern.CASE_INSENSITIVE);

    public static final EnglishWikiAreaUtil INSTANCE = new EnglishWikiAreaUtil();

    protected Pattern areaPattern;

    protected EnglishWikiAreaUtil () { this.areaPattern = enAreaPattern; }
   
    public Float getArea(CharSequence infobox) {
        try {
            Matcher m = areaPattern.matcher(infobox);
            if (m.find()) return new Float(m.group(2).replaceAll(",", ""));       	
        } catch (Exception e) {
        	e.printStackTrace();
        }
        return null;
    }

}
